package com.example.xm.ui.own;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.request.RequestOptions;
import com.example.xm.R;
import com.example.xm.adapter.ownAdapter.OwnRlvAdapter;
import com.example.xm.base.BaseFragment;
import com.example.xm.base.BasePresenter;
import com.example.xm.ui.home.activity.YouHomeActivity;
import com.example.xm.ui.own.activity.MyHomeActivity;
import com.example.xm.ui.own.activity.SettingActivity;
import com.example.xm.utiles.GildeUtils;
import com.example.xm.utiles.SpUtils;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

public class OwnFragment extends BaseFragment {


    @BindView(R.id.iv_head_bg)
    ImageView ivHeadBg;
    @BindView(R.id.rl_own)
    RelativeLayout rlOwn;
    @BindView(R.id.rlv_own)
    RecyclerView rlvOwn;
    @BindView(R.id.tv_title_own)
    TextView tvTitleOwn;
    @BindView(R.id.iv_lv_own)
    ImageView ivLvOwn;
    @BindView(R.id.tv_you_home)
    TextView tvYouHome;
    @BindView(R.id.tv_qiandao)
    TextView tvQiandao;
    @BindView(R.id.tv_dongtai_num)
    TextView tvDongtaiNum;
    @BindView(R.id.tv_dongtai)
    TextView tvDongtai;
    @BindView(R.id.ll_dongtai)
    LinearLayout llDongtai;
    @BindView(R.id.tv_guanzhu_num_own)
    TextView tvGuanzhuNumOwn;
    @BindView(R.id.tv_guanzhu_own)
    TextView tvGuanzhuOwn;
    @BindView(R.id.ll_guanzhu)
    LinearLayout llGuanzhu;
    @BindView(R.id.tv_fensi_num)
    TextView tvFensiNum;
    @BindView(R.id.tv_fensi)
    TextView tvFensi;
    @BindView(R.id.ll_fensi)
    LinearLayout llFensi;
    @BindView(R.id.tv_tongqian_num)
    TextView tvTongqianNum;
    @BindView(R.id.tv_tongqian)
    TextView tvTongqian;
    @BindView(R.id.ll_tongqian)
    LinearLayout llTongqian;
    @BindView(R.id.img_head_own)
    ImageView imgHeadOwn;
    @BindView(R.id.img_sex_own)
    ImageView imgSexOwn;
    @BindView(R.id.iv_own_setting)
    ImageView ivOwnSetting;
    private ImageView left;
    private TextView title;
    private ImageView link;
    private ImageView left1;
    private TextView title1;
    private ImageView link1;
    private ImageView link3;
    private TextView title3;
    private ImageView left3;
    private String[] tabs = {"商品收藏", "关注店铺", "优惠卡卷", "商城订单", "我的活动", "我的话题", "我喜欢的", "我的悬赏"};
    private ArrayList<String> strings;
    private ImageView left4;
    private TextView title4;
    private ImageView link4;

    @Override
    protected BasePresenter initPresenter() {
        return null;
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_own;
    }

    @Override
    protected void initView() {
        RequestOptions requestOptions = new RequestOptions().circleCrop();
        Glide.with(getActivity()).load(R.drawable.timg).apply(requestOptions).into(imgHeadOwn);
        ivHeadBg.setAlpha(0.8f);
        ivHeadBg.setImageDrawable(getResources().getDrawable(R.drawable.timg));
        strings = new ArrayList<>();
        for (int i = 0; i < tabs.length; i++) {
            strings.add(tabs[i]);
        }
        rlvOwn.setLayoutManager(new GridLayoutManager(getActivity(), 4));
        OwnRlvAdapter ownRlvAdapter = new OwnRlvAdapter(getActivity(), strings);
        rlvOwn.setAdapter(ownRlvAdapter);
        imgHeadOwn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), MyHomeActivity.class);
                intent.putExtra("uid", SpUtils.getInstance().getString("uid"));
                intent.putExtra("curuid", SpUtils.getInstance().getString("uid"));
                startActivityForResult(intent, 3);
            }
        });
        String avater = SpUtils.getInstance().getString("avater");
        GildeUtils.loadRoundImg(getActivity(), avater, imgHeadOwn);
        GildeUtils.loadImg(getActivity(), avater, ivHeadBg);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        ConstraintLayout own1 = view.findViewById(R.id.include_own1);
        left = own1.findViewById(R.id.iv_left);
        title = own1.findViewById(R.id.tv_title_include);
        link = own1.findViewById(R.id.iv_link);
        ConstraintLayout own2 = view.findViewById(R.id.include_own2);
        left1 = own2.findViewById(R.id.iv_left);
        title1 = own2.findViewById(R.id.tv_title_include);
        link1 = own2.findViewById(R.id.iv_link);
        ConstraintLayout own3 = view.findViewById(R.id.include_own3);
        left3 = own3.findViewById(R.id.iv_left);
        title3 = own3.findViewById(R.id.tv_title_include);
        link3 = own3.findViewById(R.id.iv_link);
        ConstraintLayout own4 = view.findViewById(R.id.include_own4);
        left4 = own4.findViewById(R.id.iv_left);
        title4 = own4.findViewById(R.id.tv_title_include);
        link4 = own4.findViewById(R.id.iv_link);
        title.setText("收货认证");
        title1.setText("技能认证");
        title3.setText("实名认证");
        title4.setText("邀请同袍有奖");
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {
        ivOwnSetting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), SettingActivity.class);
                startActivityForResult(intent,3);
            }
        });
    }

    @Override
    public void showTips(String tips) {

    }

    @Override
    public void showLoading(int visble) {

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 3) {
            String avater = SpUtils.getInstance().getString("avater");
            GildeUtils.loadRoundImg(getActivity(), avater, imgHeadOwn);
            GildeUtils.loadImg(getActivity(), avater, ivHeadBg);
        }
    }
}